package com.sc.nft.dao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.PushTag;
import com.sc.nft.mapper.PushTagMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * @author 刘国航
 * @desc
 * @since 2024/6/14 11:46
 */
@Slf4j
@Repository
public class PushTagDao extends ServiceImpl<PushTagMapper, PushTag> {

    public PushTag getByName(String name) {
        LambdaQueryWrapper<PushTag> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PushTag::getName, name);
        return baseMapper.selectOne(queryWrapper);
    }

    public Page<PushTag> pageByName(Page<PushTag> page, String name) {
        LambdaQueryWrapper<PushTag> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StrUtil.isNotBlank(name), PushTag::getName, name);
        queryWrapper.orderByDesc(PushTag::getId);
        return baseMapper.selectPage(page, queryWrapper);
    }

    public List<PushTag> all() {
        LambdaQueryWrapper<PushTag> queryWrapper = new LambdaQueryWrapper<>();
        return baseMapper.selectList(queryWrapper);
    }

}
